
#if defined objects_inc
 #endscript
#endif
#define objects_inc

#include <file>







stock IsValidObjectModel(omodelid)
{
	new File:fp = fopen("data/objects.dat", filemode:io_read);
	if(!fp) return true;

	new line[96], tmp[32];

	new index;

	new interval_min,
		interval_max;

	while(fread(fp, line, sizeof(line)) > 0)
	{
		if(line[0] == '#' || line[0] == '\r') continue;
		else if(line[0] == '!')
		{
			interval_max = strval(line[1]);
			if(omodelid > interval_max) return false;
			continue;
		}

		index = token_by_delim(line, tmp, ',', 0);
		if(index == -1) continue;
		interval_min = strval(tmp);
		// all object must be placed in asc order
		if(omodelid < interval_min) 
		{
			fclose(fp);
			return false;
		}

		index = token_by_delim(line, tmp, ',', index+1);
		if(index == -1) continue;
		interval_max = strval(tmp);

		if(omodelid <= interval_max) 
		{
			fclose(fp);
			return true;
		}


	}
	fclose(fp);
	return false;
}







static stock token_by_delim(const string[], return_str[], delim, start_index)
{
	new x=0;
	while(string[start_index] == ' ' || string[start_index] == '\t')
		start_index++;
	while(string[start_index] != delim && string[start_index] != EOS &&  string[start_index] != '#')
	{
		return_str[x] = string[start_index];
		++x;
		++start_index;
	}
	return_str[x] = EOS;
	if(string[start_index] == EOS) start_index = (-1);
	return start_index;
}

















